package com.lanyan.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;
        import com.lanyan.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.lanyan.common.utils.StringUtils;
import com.lanyan.system.mapper.BuildingMapper;
import com.lanyan.system.domain.Building;
import com.lanyan.system.domain.vo.BuildingVo;
import com.lanyan.system.service.IBuildingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 楼栋Service业务层处理
 *
 * @author lanyan
 * @date 2024-11-26
 */
@Service
public class BuildingServiceImpl  extends ServiceImpl<BuildingMapper,Building> implements IBuildingService

{
    @Autowired
    private BuildingMapper buildingMapper;

    /**
     * 查询楼栋
     *
     * @param buildingId 楼栋主键
     * @return 楼栋
     */
    @Override
    public Building selectBuildingByBuildingId(Long buildingId)
    {
        return this.getById(buildingId);
    }

    /**
     * 查询楼栋Vo列表
     *
     * @param building 楼栋
     * @return 楼栋
     */
    @Override
    public List<BuildingVo> selectBuildingVoList(Building building)
    {
        return selectBuildingList(building)
                .stream()
                .map(x -> (BuildingVo)x)
                .collect(Collectors.toList());
    }
    /**
     * 查询楼栋列表
     *
     * @param building 楼栋
     * @return 楼栋
     */
    @Override
    public List<Building> selectBuildingList(Building building)
    {
        LambdaQueryChainWrapper<Building> wrapper = this.lambdaQuery().eq(Building::getDelFlag,"0");
        if (StringUtils.isNotEmpty(building.getName())) {
            wrapper.like(Building::getName, building.getName());
        }
        if (building.getEstateId() != null) {
            wrapper.eq(Building::getEstateId, building.getEstateId());
        }
        if (building.getCourierId() != null) {
            wrapper.eq(Building::getCourierId, building.getCourierId());
        }
        return wrapper.list();
    }

        /**
         * 新增楼栋
         *
         * @param building 楼栋
         * @return 结果
         */
    @Override
        public boolean insertBuilding(Building building)
        {
                    building.setCreateTime(DateUtils.getNowDate());
                return this.save(building);
        }

        /**
         * 修改楼栋
         *
         * @param building 楼栋
         * @return 结果
         */
    @Override
        public boolean updateBuilding(Building building)
        {
                    building.setUpdateTime(DateUtils.getNowDate());
            return this.updateById(building);
        }

        /**
         * 批量删除楼栋
         *
         * @param buildingIds 需要删除的楼栋主键
         * @return 结果
         */
    @Override
        public boolean deleteBuildingByBuildingIds(Long[] buildingIds)
        {
            return this.lambdaUpdate().set(Building::getDelFlag,"1").in(Building::getBuildingId,buildingIds).update();
        }

        /**
         * 删除楼栋信息
         *
         * @param buildingId 楼栋主键
         * @return 结果
         */
    @Override
        public boolean deleteBuildingByBuildingId(Long buildingId)
        {
            return this.lambdaUpdate().set(Building::getDelFlag,"1").eq(Building::getBuildingId,buildingId).update();
        }
    }
